package timeUtil

import "time"

func Yesterday() time.Time {
	return CalDay(time.Now(), -1)
}

func Tomorrow() time.Time {
	return CalDay(time.Now(), 1)
}

func CalDay(t time.Time, n int) time.Time {
	return t.AddDate(0, 0, n)
}

func SetTimeZero(t time.Time) time.Time {
	ds := TimeFmtStr(t, DateFormat)
	r, _ := ParseWithFmt(DateFormat, ds)
	return r
}

// 按天进行比较      小于：-1 大于：1 等于： 0
func CompareDay(t1, t2 time.Time) int {
	d1, _ := ParseWithFmt(DateFormat, TimeFmtStr(t1, DateFormat))
	d2, _ := ParseWithFmt(DateFormat, TimeFmtStr(t2, DateFormat))
	if d1.Equal(d2) {
		return 0
	} else if d1.After(d2) {
		return 1
	} else {
		return -1
	}
}
